#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
using ll = long long;

void solve() {
	int n;
	cin >> n;
	vector<ll> a(2 * n);
	
	for (int i = 0; i < 2 * n; i++) {
		cin >> a[i];
	}
	
	ll ans = 0;
	for (int i = 33; i >= 0; i--) {
		ll want = ans | (1LL << i);
		
		int count = 0;
		for (ll x : a) {
			if ((x & want) == want) {
				count++;
			}
		}
		
		if (count >= n) {
			ans = want; 
		}
	}
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

